import { setToken, getToken, delToken } from '@/utils/storage.js'
import { login } from '@/api/user.js'
export default {
  state () {
    return {
      token: getToken()
    }
  },
  mutations: {
    fn (state, token) {
      state.token = token
    },
    tc (state) {
      state.token = null
      delToken()
    }
  },
  actions: {
    async asyncLogin ({ commit }, ruleForm) {
      const res = await login(ruleForm)
      console.log(res);
      commit('fn', res.data.token)
      setToken(res.data.token)
    },
  },
  getters: {},
  namespaced: true
}
